﻿using System;
using System.Collections;
using System.Configuration;
using System.Data; 
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Entity;
using System.Collections.Generic;
using Runda.CMS.Bll; 

namespace Runda.CMS.Portal.ContractManage
{
    public partial class ContractChangeList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRoleList(1);
            }
        }

        private void BindRoleList(int pageindex)
        {
            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            SqlDbParameter parm = null;

            parm = new SqlDbParameter();
            parm.ColumnName = "CreatedBy";
            parm.ColumnType = DbType.Guid;
            parm.ParameterName = "@CreatedBy";
            parm.ParameterValue = base.CurrentUserID;
            parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
            parms.Add(parm);

            parm = new SqlDbParameter();
            parm.ColumnName = "Status";
            parm.ColumnType = DbType.Int32;
            parm.ParameterName = "@Status";
            parm.ParameterValue = (int)Enumerator.ContractStatus.Pass;
            parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
            parms.Add(parm);

            if (txtContractCode.Text != string.Empty)
            {
                parm = new SqlDbParameter();
                parm.ColumnName = "ContractCode";
                parm.ColumnType = DbType.String;
                parm.ParameterName = "@ContractCode";
                parm.ParameterValue = txtContractCode.Text;
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Like;
                parms.Add(parm);
            }

            int RecordCount = 0;
            List<CtrtContractEntity> list = new CtrtContractBll().GetAll<CtrtContractEntity>(parms, "createdon desc", AspNetPager1.PageSize, pageindex, out RecordCount);

            RepeaterContract.DataSource = list;
            RepeaterContract.DataBind();
            AspNetPager1.RecordCount = RecordCount;
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindRoleList(1);
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindRoleList(AspNetPager1.CurrentPageIndex);
        }

        public string GetStatusText(int status)
        {
            string text = string.Empty;
            EnumeratorHelper[] cs = EnumeratorHelper.GetFieldTexts(typeof(Enumerator.ContractStatus));
            foreach (EnumeratorHelper c in cs)
            {
                if (c.EnumValue == status)
                {
                    text = c.EnumDisplayText; break;
                }
            }

            return text;
        }

        protected void RepeaterContract_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                BindRoleList(1);
            }
        }
    }
}
